<template>
  <div class="nav-header">
    <el-icon class="fold-menu">
      <component :is="isFold ? 'Expand' : 'Fold'" @click="handleFoldClick" />
    </el-icon>
    <div class="content">
      <jg-breadcrumb :breadcrumbs="breadcrumbs" />
      <user-info />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, computed } from 'vue'
import UserInfo from './user-info.vue'
import JgBreadcrumb from '@/base-ui/breadcrumb'
import { useStore } from '@/store'
import { useRoute } from 'vue-router'
import { pathMapBreadcrumbs } from '@/utils/map-menus'
//使用emits将isFold.value值传出去
export default defineComponent({
  components: {
    UserInfo,
    JgBreadcrumb
  },
  emits: ['foldChange'],
  setup(props, { emit }) {
    const isFold = ref(false)
    const handleFoldClick = () => {
      isFold.value = !isFold.value
      emit('foldChange', isFold.value)
    }
    const store = useStore()
    const breadcrumbs = computed(() => {
      const userMenus = store.state.loginModule.userMenus
      const route = useRoute()
      return pathMapBreadcrumbs(userMenus, route.path)
    })
    return { isFold, handleFoldClick, breadcrumbs }
  }
})
</script>

<style scoped lang="less">
.nav-header {
  display: flex;
  width: 100%;
  .fold-menu {
    font-size: 30px;
    cursor: pointer;
  }
  .content {
    display: flex;
    align-items: center;
    padding: 0 15px;
    justify-content: space-between;
    flex: 1;
  }
}
</style>
